﻿using System;
using System.Collections;
using System.Collections.Generic;

using IBatisNet.DataAccess;

using AUV5.Model;
using AUV5.DAL;
using AUV5.DAL.Interface;
using AUV5.DAL.Dao;

namespace AUV5.BLL
{
    /// <summary>
    /// 功能：     WithDrawLog业务逻辑实现
    /// 作者：     Wilson
    /// 日期：     2012/1/17
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class WithDrawLogBLL
    {
        private static WithDrawLogBLL instance = new WithDrawLogBLL();
        private IDaoManager daoManager = ServiceConfig.Instance.DaoManager;
        private IWithDrawLogDao dao = null;

        private WithDrawLogBLL()
        {
            dao = WithDrawLogSqlMapDao.GetInstance();
        }

        public static WithDrawLogBLL GetInstance()
        {
            return instance;
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                //daoManager.BeginTransaction();

                int count = dao.GetMaxCounts();

                //daoManager.CommitTransaction();

                return count;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<WithDrawLog> GetList()
        {
            try
            {
                //daoManager.BeginTransaction();

                System.Collections.Generic.IList<WithDrawLog> list = dao.GetList();

                //daoManager.CommitTransaction();

                return list;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="TopCounts"></param>
        /// <returns></returns>
        private System.Collections.Generic.IList<WithDrawLog> GetListByParameters(object TopCounts, WithDrawLog withdrawlog)
        {
            try
            {
                //daoManager.BeginTransaction();

                Hashtable ht = new Hashtable();
                ht.Add("TopCounts", TopCounts);
                System.Collections.Generic.IList<WithDrawLog> list = dao.GetListByParameters(ht);

                //daoManager.CommitTransaction();

                return list;
            }
            catch
            {
                //daoManager.RollBackTransaction();
                throw;
            }
        }


        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="WithdrawLogID"></param>
        /// <returns></returns>
        public WithDrawLog GetDetail(System.String withdrawlogid)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.GetDetail(withdrawlogid);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }


        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="withdrawlog"></param>
        /// <returns></returns>
        public object Add(WithDrawLog withdrawlog)
        {
            //int id = GetId("SYS_UserInfoTemp");
            //sys_userinfotemp.UserID = id;

            try
            {
                ///daoManager.BeginTransaction();
                withdrawlog.CreateDate = DateTime.Now;
                withdrawlog.UpdateDate = DateTime.Now;
                withdrawlog.LastStatus = Convert.ToInt32(AUV5.Common.Enum.auvWithDrawStatus.IsRequest);
                withdrawlog.WithDrawStatus = Convert.ToInt32(AUV5.Common.Enum.auvWithDrawStatus.IsRequest);
                return dao.Add(withdrawlog);
                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="withdrawlog"></param>
        /// <returns></returns>
        public int Update(WithDrawLog withdrawlog)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Update(withdrawlog);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="WithdrawLogID"></param>
        /// <returns></returns>
        public int Delete(System.String withdrawlogid)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Delete(withdrawlogid);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="withdrawlog"></param>
        /// <returns></returns>
        public int Delete(WithDrawLog withdrawlog)
        {
            try
            {
                ///daoManager.BeginTransaction();

                return dao.Delete(withdrawlog);

                ///daoManager.CommitTransaction();
            }
            catch
            {
                ///daoManager.RollBackTransaction();
                throw;
            }
        }


        #region##得到提现总额
        /// <summary>
        /// 得到提现总额
        /// 创建人：Wilson
        /// 创建时间：2012-1-17
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public decimal GetTotalAmountByUserId(string userId)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("UserID",userId);
                ht.Add("BeginStatus",Convert.ToInt32(AUV5.Common.Enum.auvWithDrawStatus.Backout));
                ht.Add("EndStatus",Convert.ToInt32(AUV5.Common.Enum.auvWithDrawStatus.Closed));
                return dao.GetTotalAmountByUserId(ht);
            }
            catch
            {
                throw;
            }
        }
        #endregion

        #region##通过UserId得到提现记录集合
        /// <summary>
        /// 通过UserId得到提现记录集合
        /// 创建人：Wilson
        /// 创建时间：2012-1-17     
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public IList<WithDrawLog> GetWithDrawListByUserId(string userId)
        {
            try
            {
                return dao.GetWithDrawListByUserId(userId);
            }
            catch
            {
                throw;
            }
        }
        #endregion
    }
}
